/*
 * @Author: 颜锦忠
 * @Date: 2021-04-06 09:49:40
 */
import { ref } from 'vue';
import { useRouter, useRoute } from 'vue-router';

interface IRouter {
  name: string;
  query?: any;
  params?: any;
}

export const router = (): any => {
  const { name, query, params, meta, path, fullPath, matched } = useRoute();
  const { push, currentRoute, options } = useRouter();
  const handleRouterJump = (data: IRouter): void => {
    push(data);
  };
  const initBreadCrumbItems = (data: any): any[] => {
    const breadCrumbItemList = ref<any[]>([{ path: '/', title: '垃圾费管理系统' }]);
    data.forEach((item: any): void => {
      if (item.meta && item.meta.title) {
        breadCrumbItemList.value.push({
          path: item.path,
          title: item.meta.title,
        });
      }
    });
    return breadCrumbItemList.value;
  };

  return {
    name,
    query,
    params,
    meta,
    path,
    fullPath,
    matched,
    handleRouterJump,
    currentRoute,
    push,
    options,
    initBreadCrumbItems,
  };
};
